package com.pjmike.netty.server.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author pjmike
 * @create 2018-10-24 15:43
 */
@Slf4j
@ChannelHandler.Sharable
public class NettyServerHandler extends SimpleChannelInboundHandler<String> {

//    @Override
//    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
////        String heartbeatType = "heart";
////        String businessType = "business";
//        MessageContext context = (MessageContext)SpringContextUtil.getBean("messageContext");
//        String message = context.doDispatcher(msg);
//        if(message!=null){
//            ctx.writeAndFlush(message);
//        }
//    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("连接的客户端地址:" + ctx.channel().remoteAddress());
        super.channelActive(ctx);
    }
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.info("断开连接的客户端地址:" + ctx.channel().remoteAddress());
        ctx.channel().close();
    }
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, String s) throws Exception {

    }
}
